<?php

namespace app\index\controller;


use think\Controller;

class Indextest extends Controller
{

    public function test(){

       $xml='<?xml version="1.0" encoding="utf-8"?><request><type>card_cz_que</type><price>1</price><merchid>501</merchid><orderid></orderid><code>938482966806</code><user>lsz001</user><csid></csid><cate>price</cate></request>';
           $data=$this->xml_to_array($xml);


//        $res=action('api/api/api',array($data));
        var_dump($data);
    }
    public function xml_to_array($xml)
    {
        libxml_disable_entity_loader(true);

        $xmlstring = (array)simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);

        $val = json_decode(json_encode($xmlstring),true);

        return $this->unsetNull($val);

    }
    public function unsetNull($arr){
        if($arr !== null){
            if(is_array($arr)){
                if(!empty($arr)){
                    foreach($arr as $key => $value){
                        if($value === null){
                            $arr[$key] = '';
                        }else{
                            $arr[$key] = $this->unsetNull($value);      //递归再去执行
                        }
                    }
                }else{ $arr = ''; }
            }else{
                if($arr === null){ $arr = ''; }         //注意三个等号
            }
        }else{ $arr = ''; }
        return $arr;
    }


}
